******SET YOUR DIRECTORY to ...\replication


clear all
set more off


///////////////////////////////////////////////////////////////
///TABLE A.4///////////////////////////////////////////////////
///////////////////////////////////////////////////////////////

use "finaldata\final_cc_data.dta", clear

drop if fipsplace_00==.
xtset fipsplace_00 year

drop if year>1991

*Create instrument and outcome
g good_soil = (ph1_plc_wtm_wtm_0_r>=6.8 & ph1_plc_wtm_wtm_0_r<=7.7)
gen bad_soil=1-good_soil
gen inter_goodtetra=good_soil*tetra_corr
gen inter_badtetra=(1-good_soil)*tetra_corr
g perc_cc =  tot_cc_oripop_corr / (tot_ncc_oripop_corr + tot_cc_oripop_corr)
g pop_msa = tot_ncc_oripop_corr + tot_cc_oripop_corr

*Create dependent variables
gen vc_pc=totnpcc_cc_offenses_vc*1000
gen vc_ncc_pc=totnpcc_ncc_offenses_vc*1000
g lnpop_cc = ln(tot_cc_oripop_corr)
g lnpop_ncc = ln(tot_ncc_oripop_corr)
gen lnpop_msa=ln(pop_msa)

*Create aggregate variables
egen vcn_cc_us=total( totn_cc_offenses_vc),by(year)
egen vcn_ncc_us=total( totn_ncc_offenses_vc),by(year)
egen pop_cc_us=total(tot_cc_oripop_corr),by(year)
egen pop_ncc_us=total(tot_ncc_oripop_corr),by(year)
gen vcnpcc_cc_us=vcn_cc_us/pop_cc_us
gen vcnpcc_ncc_us=vcn_ncc_us/pop_ncc_us
gen perc_cc_us=pop_cc_us/(pop_cc_us+pop_ncc_us)
gen lnpop_cc_us=ln(pop_cc_us)
gen lnpop_ncc_us=ln(pop_ncc_us)
egen vcn_cc_lowlb_us_2=total( totn_cc_offenses_vc) if good_soil==1,by(year)
egen vcn_cc_lowlb_us=max(vcn_cc_lowlb_us_2),by(year)
egen pop_cc_lowlb_us_2=total(tot_cc_oripop_corr) if good_soil==1,by(year)
egen pop_cc_lowlb_us=max(pop_cc_lowlb_us_2),by(year)
gen vcnpcc_cc_lowlb_us=vcn_cc_lowlb_us/pop_cc_lowlb_us

*Cluster variables
egen cdivcodeyear=group(cdivcode year)

*Label variables
label var vc_pc "Violent crime"
label var inter_badtetra "High LB x Lead"

drop if tot_ncc_oripop_corr == .


***Quantification magnitudes
*Change in vc CC 60-91
sum vc_pc if year==1960
local vc_pc_60 =`r(mean)'
sum vc_pc if year==1991
local vc_pc_91 =`r(mean)'
local dvc_pc_6091=`vc_pc_91'-`vc_pc_60'
display  "Change VC: 91-60 (Predicted level high LB in 91) " `dvc_pc_6091' " VC: 91 " `vc_pc_91' " VC: 60 " `vc_pc_60'
*Population CC and NCC in 1960
sum tot_cc_oripop_corr if year==1960
local pop_cc_60=`r(mean)'
sum tot_ncc_oripop_corr if year==1960
local pop_ncc_60=`r(mean)'
*Population CC in 1991
sum tot_cc_oripop_corr if year==1991
local pop_cc_91=`r(mean)'
*Relative crime CC/NCC
sum vc_pc if year==1960
local vc_cc_60 =`r(mean)'
sum vc_pc if year==1991
local vc_cc_91 =`r(mean)'
local dvc_cc_6091=`vc_cc_91'-`vc_cc_60'
display `dvc_cc_6091'
sum vc_ncc_pc if year==1960
local vc_ncc_60 =`r(mean)'
sum vc_ncc_pc if year==1991
local vc_ncc_91 =`r(mean)'
local dvc_ncc_6091=`vc_ncc_91'-`vc_ncc_60'
display `dvc_ncc_6091'
di `dvc_cc_6091'/`dvc_ncc_6091'

*First stage
reghdfe vc_pc inter_badtetra, abs(fipsplace_00 year cdivcode#year) cluster(cdivcodeyear)
local dvc_highlb_6091=`dvc_pc_6091'-_b[inter_badtetra]
display `dvc_highlb_6091'


*Change in lead
sum tetra_corr if year==1960
local dlead_6091=1-`r(mean)'
display `dlead_6091'

*National parameters
su vcnpcc_cc_us if year==1960
local vcpc_cc_60 = r(mean)
g delta_vc_noinc = vcnpcc_cc_us - `vcpc_cc_60'
su vcnpcc_ncc_us if year==1960
local vcpc_ncc_60 = r(mean)
g delta_vc_incncc = vcnpcc_cc_us - `vcpc_cc_60'+`vcpc_ncc_60'
su vcnpcc_cc_lowlb_us if year==1960
local vcpc_lowlb_60 = r(mean)
g delta_vc_inclowlb = vcnpcc_cc_us - `vcpc_cc_60'+`vcpc_lowlb_60'

*Summary national changes in VC
su vcnpcc_cc_us if year==1960
di `r(mean)'*1000
su vcnpcc_cc_us if year==1991
di `r(mean)'*1000
su vcnpcc_ncc_us if year==1960
di `r(mean)'*1000
su vcnpcc_ncc_us if year==1991
di `r(mean)'*1000
su vcnpcc_cc_lowlb_us if year==1960
di `r(mean)'*1000
su vcnpcc_cc_lowlb_us if year==1991
di `r(mean)'*1000

file open myfile using table_magnitude.txt, write replace
file write myfile "\begin{tabular}{l c cccc c} \hline\hline \textbf{Increase in VC CC from 1960 to 1991}  &  & \multicolumn{4}{c}{\textbf{Change from 1960 to 1991}} & \textbf{Counterfactual} \\ \cline{3-7} \\ \textbf{Counterfactual VC}  &  & \textbf{Pop CC} & \textbf{Pop CC \%} & \textbf{Pop CC in US (mil.)} & \textbf{Pop NCC} & \textbf{av. Pop CC 1991} \\  \hline" _n

**If VC CC increases from 1960 to level in 1991
**Counterfactual VC keep as 1960
*Change Pop CC
ivreghdfe lnpop_cc (vc_pc = inter_badtetra), abs(fipsplace_00 year cdivcode#year) cluster(cdivcodeyear)
*Total loss in Pop CC
nlcom _b[vc_pc]*`dvc_pc_6091'*`pop_cc_60'
local aaa_b=r(b)[1,1]
local aa_b = string(`aaa_b',"%8.0f")
matrix define ress = r(V)
local aaa_se = sqrt(ress[1,1])
local aa_se = string(`aaa_se',"%8.0f")
*% loss in Pop CC
nlcom _b[vc_pc]*`dvc_pc_6091'
local bbb_b=r(b)[1,1]*100
local bb_b = string(`bbb_b',"%8.1f")
matrix define ress = r(V)
local bbb_se = sqrt(ress[1,1])*100
local bb_se = string(`bbb_se',"%8.1f")
*Total loss in Pop CC in US
nlcom _b[vc_pc]*`dvc_pc_6091'*`pop_cc_60'*325
local ccc_b=r(b)[1,1]/1000000
local cc_b = string(`ccc_b',"%8.1f")
matrix define ress = r(V)
local ccc_se = sqrt(ress[1,1])/1000000
local cc_se = string(`ccc_se',"%8.1f")
*Change Pop NCC
ivreghdfe lnpop_ncc (vc_pc = inter_badtetra), abs(fipsplace_00 year cdivcode#year) cluster(cdivcodeyear)
nlcom _b[vc_pc]*`dvc_pc_6091'*`pop_ncc_60'
local ddd_b=r(b)[1,1]
local dd_b = string(`ddd_b',"%8.0f")
matrix define ress = r(V)
local ddd_se = sqrt(ress[1,1])
local dd_se = string(`ddd_se',"%8.0f")
*Counterfactual Pop CC
ivreghdfe lnpop_cc (totnpcc_cc_offenses_vc = inter_goodtetra), abs(fipsplace_00 year cdivcode#year) cluster(cdivcodeyear)
gen pop_cc_us_counter_noinc=exp(lnpop_cc_us-(_b[totnpcc_cc_offenses_vc]*delta_vc_noinc))/325
sum pop_cc_us_counter_noinc if year==1991
local eee_b=`r(mean)'
local ee_b = string(`eee_b',"%8.0f")
gen pop_cc_us_counter_noinc_h=exp(lnpop_cc_us-((_b[totnpcc_cc_offenses_vc]-1.96*_se[totnpcc_cc_offenses_vc])*delta_vc_noinc))/325
gen pop_cc_us_counter_noinc_l=exp(lnpop_cc_us-((_b[totnpcc_cc_offenses_vc]+1.96*_se[totnpcc_cc_offenses_vc])*delta_vc_noinc))/325
gen se_counter_noinc=(-(pop_cc_us_counter_noinc_l-pop_cc_us_counter_noinc)/1.96)
sum se_counter_noinc if year==1991
local eee_se=`r(mean)'
local ee_se = string(`eee_se',"%8.0f")

file write myfile  %11.2f ("Do not change from 1960") _tab "&" _tab _tab "&"  _tab %11.2f ("`aa_b'") _tab "&" _tab %11.2f ("`bb_b' \%") _tab "&"  _tab %8.2f ("`cc_b' mil.") _tab "&" _tab %8.2f ("`dd_b'") _tab  "&" _tab %8.2f ("`ee_b'") _tab "\\" _n

file write myfile   "&"  "&"  _tab %11.2f ("(`aa_se')") _tab "&" _tab %11.2f ("(`bb_se')") _tab "&"  _tab %8.2f ("(`cc_se')") _tab "&" _tab %8.2f ("(`dd_se')") _tab  "&" _tab %8.2f ("(`ee_se')") _tab  "\\" _n 


**if VC CC increased from level in 1960 to level in 1991
**Counterfactual that VC increase from 1960 to 1991 as in NCC
*Change Pop CC
ivreghdfe lnpop_cc (vc_pc = inter_badtetra), abs(fipsplace_00 year cdivcode#year) cluster(cdivcodeyear)
*Total loss in Pop CC
nlcom _b[vc_pc]*(`dvc_pc_6091'-`dvc_ncc_6091')*`pop_cc_60'
local aaa_b=r(b)[1,1]
local aa_b = string(`aaa_b',"%8.0f")
matrix define ress = r(V)
local aaa_se = sqrt(ress[1,1])
local aa_se = string(`aaa_se',"%8.0f")
*% loss in Pop CC
nlcom _b[vc_pc]*(`dvc_pc_6091'-`dvc_ncc_6091')
local bbb_b=r(b)[1,1]*100
local bb_b = string(`bbb_b',"%8.1f")
matrix define ress = r(V)
local bbb_se = sqrt(ress[1,1])*100
local bb_se = string(`bbb_se',"%8.1f")
*Total loss in Pop CC in US
nlcom _b[vc_pc]*(`dvc_pc_6091'-`dvc_ncc_6091')*`pop_cc_60'*325
local ccc_b=r(b)[1,1]/1000000
local cc_b = string(`ccc_b',"%8.1f")
matrix define ress = r(V)
local ccc_se = sqrt(ress[1,1])/1000000
local cc_se = string(`ccc_se',"%8.1f")
*Change Pop NCC
ivreghdfe lnpop_ncc (vc_pc = inter_badtetra), abs(fipsplace_00 year cdivcode#year) cluster(cdivcodeyear)
nlcom _b[vc_pc]*(`dvc_pc_6091'-`dvc_ncc_6091')*`pop_ncc_60'
local ddd_b=r(b)[1,1]
local dd_b = string(`ddd_b',"%8.0f")
matrix define ress = r(V)
local ddd_se = sqrt(ress[1,1])
local dd_se = string(`ddd_se',"%8.0f")
*Counterfactual Pop CC
ivreghdfe lnpop_cc (totnpcc_cc_offenses_vc = inter_goodtetra), abs(fipsplace_00 year cdivcode#year) cluster(cdivcodeyear)
gen pop_cc_us_counter_incncc=exp(lnpop_cc_us-(_b[totnpcc_cc_offenses_vc]*delta_vc_incncc)+_b[totnpcc_cc_offenses_vc]*vcnpcc_ncc_us)/325
sum pop_cc_us_counter_incncc if year==1991
local eee_b=`r(mean)'
local ee_b = string(`eee_b',"%8.0f")
gen pop_cc_us_counter_incncc_h=exp(lnpop_cc_us-((_b[totnpcc_cc_offenses_vc]-1.96*_se[totnpcc_cc_offenses_vc])*delta_vc_incncc)+((_b[totnpcc_cc_offenses_vc]-1.96*_se[totnpcc_cc_offenses_vc])*vcnpcc_ncc_us))/325
gen pop_cc_us_counter_incncc_l=exp(lnpop_cc_us-((_b[totnpcc_cc_offenses_vc]+1.96*_se[totnpcc_cc_offenses_vc])*delta_vc_incncc)+((_b[totnpcc_cc_offenses_vc]+1.96*_se[totnpcc_cc_offenses_vc])*vcnpcc_ncc_us))/325
gen se_counter_incncc=(-(pop_cc_us_counter_incncc_l-pop_cc_us_counter_incncc)/1.96)
sum se_counter_incncc if year==1991
local eee_se=`r(mean)'
local ee_se = string(`eee_se',"%8.0f")

file write myfile  %11.2f ("Change as in NCC") _tab "&" _tab _tab "&"  _tab %11.2f ("`aa_b'") _tab "&" _tab %11.2f ("`bb_b' \%") _tab "&"  _tab %8.2f ("`cc_b' mil.") _tab "&" _tab %8.2f ("`dd_b'") _tab  "&" _tab %8.2f ("`ee_b'") _tab "\\" _n

file write myfile   "&"  "&"  _tab %11.2f ("(`aa_se')") _tab "&" _tab %11.2f ("(`bb_se')") _tab "&"  _tab %8.2f ("(`cc_se')") _tab "&" _tab %8.2f ("(`dd_se')") _tab  "&" _tab %8.2f ("(`ee_se')") _tab  "\\" _n 



**if VC CC increased from level in 1960 to level in 1991
**Counterfactual that VC increase from 1960 to 1991 as in low LB
*Change Pop CC
ivreghdfe lnpop_cc (vc_pc = inter_badtetra), abs(fipsplace_00 year cdivcode#year) cluster(cdivcodeyear)
*Total loss in Pop CC
nlcom _b[vc_pc]*(`dvc_pc_6091'-`dvc_highlb_6091')*`pop_cc_60'
local aaa_b=r(b)[1,1]
local aa_b = string(`aaa_b',"%8.0f")
matrix define ress = r(V)
local aaa_se = sqrt(ress[1,1])
local aa_se = string(`aaa_se',"%8.0f")
*% loss in Pop CC
nlcom _b[vc_pc]*(`dvc_pc_6091'-`dvc_highlb_6091')
local bbb_b=r(b)[1,1]*100
local bb_b = string(`bbb_b',"%8.1f")
matrix define ress = r(V)
local bbb_se = sqrt(ress[1,1])*100
local bb_se = string(`bbb_se',"%8.1f")
*Total loss in Pop CC in US
nlcom _b[vc_pc]*(`dvc_pc_6091'-`dvc_highlb_6091')*`pop_cc_60'*325
local ccc_b=r(b)[1,1]/1000000
local cc_b = string(`ccc_b',"%8.1f")
matrix define ress = r(V)
local ccc_se = sqrt(ress[1,1])/1000000
local cc_se = string(`ccc_se',"%8.1f")
*Change Pop NCC
ivreghdfe lnpop_ncc (vc_pc = inter_badtetra), abs(fipsplace_00 year cdivcode#year) cluster(cdivcodeyear)
nlcom _b[vc_pc]*(`dvc_pc_6091'-`dvc_highlb_6091')*`pop_ncc_60'
local ddd_b=r(b)[1,1]
local dd_b = string(`ddd_b',"%8.0f")
matrix define ress = r(V)
local ddd_se = sqrt(ress[1,1])
local dd_se = string(`ddd_se',"%8.0f")
*Counterfactual Pop CC
ivreghdfe lnpop_cc (totnpcc_cc_offenses_vc = inter_goodtetra), abs(fipsplace_00 year cdivcode#year) cluster(cdivcodeyear)
gen pop_cc_us_counter_inclowlb=exp(lnpop_cc_us-(_b[totnpcc_cc_offenses_vc]*delta_vc_inclowlb)+_b[totnpcc_cc_offenses_vc]*vcnpcc_cc_lowlb_us)/325
sum pop_cc_us_counter_inclowlb if year==1991
local eee_b=`r(mean)'
local ee_b = string(`eee_b',"%8.0f")
gen pop_cc_us_counter_inclowlb_h=exp(lnpop_cc_us-((_b[totnpcc_cc_offenses_vc]-1.96*_se[totnpcc_cc_offenses_vc])*delta_vc_inclowlb)+((_b[totnpcc_cc_offenses_vc]-1.96*_se[totnpcc_cc_offenses_vc])*vcnpcc_cc_lowlb_us))/325
gen pop_cc_us_counter_inclowlb_l=exp(lnpop_cc_us-((_b[totnpcc_cc_offenses_vc]+1.96*_se[totnpcc_cc_offenses_vc])*delta_vc_inclowlb)+((_b[totnpcc_cc_offenses_vc]+1.96*_se[totnpcc_cc_offenses_vc])*vcnpcc_cc_lowlb_us))/325
gen se_counter_inclowlb=(-(pop_cc_us_counter_inclowlb_l-pop_cc_us_counter_inclowlb)/1.96)
sum se_counter_inclowlb if year==1991
local eee_se=`r(mean)'
local ee_se = string(`eee_se',"%8.0f")

file write myfile  %11.2f ("Change as in low LB") _tab "&" _tab _tab "&"  _tab %11.2f ("`aa_b'") _tab "&" _tab %11.2f ("`bb_b' \%") _tab "&"  _tab %8.2f ("`cc_b' mil.") _tab "&" _tab %8.2f ("`dd_b'") _tab  "&" _tab %8.2f ("`ee_b'") _tab "\\" _n

file write myfile   "&"  "&"  _tab %11.2f ("(`aa_se')") _tab "&" _tab %11.2f ("(`bb_se')") _tab "&"  _tab %8.2f ("(`cc_se')") _tab "&" _tab %8.2f ("(`dd_se')") _tab  "&" _tab %8.2f ("(`ee_se')") _tab  "\\" _n 


file write myfile "\hline \end{tabular}"
file close myfile





///////////////////////////////////////////////////////////////////////////////////////////
///FIGURE A.8 - A.9 - A.10
///////////////////////////////////////////////////////////////////////////////////////////
use "finaldata\final_cc_data.dta", clear

drop if fipsplace_00==.
xtset fipsplace_00 year

drop if year>1991
drop if year<1960 

*Create instrument and outcome
g good_soil = (ph1_plc_wtm_wtm_0_r>=6.8 & ph1_plc_wtm_wtm_0_r<=7.7)
gen inter_goodtetra=good_soil*tetra_corr
g perc_cc =  tot_cc_oripop_corr / (tot_ncc_oripop_corr + tot_cc_oripop_corr)
g pop_msa = tot_ncc_oripop_corr + tot_cc_oripop_corr
g lnpop_cc = ln(tot_cc_oripop_corr)
g lnpop_ncc = ln(tot_ncc_oripop_corr)
gen lnpop_msa=ln(pop_msa)

*Create aggregate variables
egen vcn_cc_us=total( totn_cc_offenses_vc),by(year)
egen vcn_ncc_us=total( totn_ncc_offenses_vc),by(year)
egen pop_cc_us=total(tot_cc_oripop_corr),by(year)
egen pop_ncc_us=total(tot_ncc_oripop_corr),by(year)
gen vcnpcc_cc_us=vcn_cc_us/pop_cc_us
gen vcnpcc_ncc_us=vcn_ncc_us/pop_ncc_us
gen perc_cc_us=pop_cc_us/(pop_cc_us+pop_ncc_us)
gen lnpop_cc_us=ln(pop_cc_us)
gen lnpop_ncc_us=ln(pop_ncc_us)
egen vcn_cc_lowlb_us_2=total( totn_cc_offenses_vc) if good_soil==1,by(year)
egen vcn_cc_lowlb_us=max(vcn_cc_lowlb_us_2),by(year)
egen pop_cc_lowlb_us_2=total(tot_cc_oripop_corr) if good_soil==1,by(year)
egen pop_cc_lowlb_us=max(pop_cc_lowlb_us_2),by(year)
gen vcnpcc_cc_lowlb_us=vcn_cc_lowlb_us/pop_cc_lowlb_us

*Cluster variables
egen cdivcodeyear=group(cdivcode year)

*Obtain parameters and construct counterfactual
su vcnpcc_cc_us if year==1960
local vcpc_cc_60 = r(mean)
g delta_vc_noinc = vcnpcc_cc_us - `vcpc_cc_60'
su vcnpcc_ncc_us if year==1960
local vcpc_ncc_60 = r(mean)
g delta_vc_incncc = vcnpcc_cc_us - `vcpc_cc_60'+`vcpc_ncc_60'
su vcnpcc_cc_lowlb_us if year==1960
local vcpc_lowlb_60 = r(mean)
g delta_vc_inclowlb = vcnpcc_cc_us - `vcpc_cc_60'+`vcpc_lowlb_60'

*Counterfactual pop CC U.S. without increase in crime in CC from 1960
*reghdfe perc_cc i.year (totnpcc_cc_offenses_vc = inter_goodtetra), abs(fipsplace_00) vce(conventional)
*ivreghdfe perc_cc i.year (totnpcc_cc_offenses_vc = inter_goodtetra), abs(fipsplace_00) robust
ivreghdfe lnpop_cc (totnpcc_cc_offenses_vc = inter_goodtetra), abs(fipsplace_00 year cdivcode#year) cluster(cdivcodeyear)
gen pop_cc_us_counter_noinc=exp(lnpop_cc_us-(_b[totnpcc_cc_offenses_vc]*delta_vc_noinc))
gen pop_cc_us_counter_noinc_h=exp(lnpop_cc_us-((_b[totnpcc_cc_offenses_vc]-1.96*_se[totnpcc_cc_offenses_vc])*delta_vc_noinc))
gen pop_cc_us_counter_noinc_l=exp(lnpop_cc_us-((_b[totnpcc_cc_offenses_vc]+1.96*_se[totnpcc_cc_offenses_vc])*delta_vc_noinc))
sort year
label var pop_cc_us "Real"
label var pop_cc_us_counter_noinc "Counter. no incr in VC in CC"
label var pop_cc_us_counter_noinc_l "Counter. l.b."
label var pop_cc_us_counter_noinc_h "Counter. u.b."
*Counterfactual poc CC U.S. with increase in crime in CC from 1960 as in NCC
gen pop_cc_us_counter_incncc=exp(lnpop_cc_us-(_b[totnpcc_cc_offenses_vc]*delta_vc_incncc)+_b[totnpcc_cc_offenses_vc]*vcnpcc_ncc_us)
gen pop_cc_us_counter_incncc_h=exp(lnpop_cc_us-((_b[totnpcc_cc_offenses_vc]-1.96*_se[totnpcc_cc_offenses_vc])*delta_vc_incncc)+((_b[totnpcc_cc_offenses_vc]-1.96*_se[totnpcc_cc_offenses_vc])*vcnpcc_ncc_us))
gen pop_cc_us_counter_incncc_l=exp(lnpop_cc_us-((_b[totnpcc_cc_offenses_vc]+1.96*_se[totnpcc_cc_offenses_vc])*delta_vc_incncc)+((_b[totnpcc_cc_offenses_vc]+1.96*_se[totnpcc_cc_offenses_vc])*vcnpcc_ncc_us))
sort year
label var pop_cc_us "Real"
label var pop_cc_us_counter_incncc "Counter. incr in VC as NCC"
label var pop_cc_us_counter_incncc_l "Counter. l.b."
label var pop_cc_us_counter_incncc_h "Counter. u.b."
*Counterfactual poc CC U.S. with increase in crime in CC from 1960 in high LB as in low LB
gen pop_cc_us_counter_inclowlb=exp(lnpop_cc_us-(_b[totnpcc_cc_offenses_vc]*delta_vc_inclowlb)+_b[totnpcc_cc_offenses_vc]*vcnpcc_cc_lowlb_us)
gen pop_cc_us_counter_inclowlb_h=exp(lnpop_cc_us-((_b[totnpcc_cc_offenses_vc]-1.96*_se[totnpcc_cc_offenses_vc])*delta_vc_inclowlb)+((_b[totnpcc_cc_offenses_vc]-1.96*_se[totnpcc_cc_offenses_vc])*vcnpcc_cc_lowlb_us))
gen pop_cc_us_counter_inclowlb_l=exp(lnpop_cc_us-((_b[totnpcc_cc_offenses_vc]+1.96*_se[totnpcc_cc_offenses_vc])*delta_vc_inclowlb)+((_b[totnpcc_cc_offenses_vc]+1.96*_se[totnpcc_cc_offenses_vc])*vcnpcc_cc_lowlb_us))
sort year
label var pop_cc_us "Real"
label var pop_cc_us_counter_inclowlb "Counter. incr in VC as low LB"
label var pop_cc_us_counter_inclowlb_l "Counter. l.b."
label var pop_cc_us_counter_inclowlb_h "Counter. u.b."

*Counterfactual pop NCC U.S. without increase in crime in CC from 1960
*reghdfe perc_cc i.year (totnpcc_cc_offenses_vc = inter_goodtetra), abs(fipsplace_00) vce(conventional)
*ivreghdfe perc_cc i.year (totnpcc_cc_offenses_vc = inter_goodtetra), abs(fipsplace_00) robust
ivreghdfe lnpop_ncc (totnpcc_cc_offenses_vc = inter_goodtetra), abs(fipsplace_00 year cdivcode#year) cluster(cdivcodeyear)
gen pop_ncc_us_counter_noinc=exp(lnpop_ncc_us-(_b[totnpcc_cc_offenses_vc]*delta_vc_noinc))
gen pop_ncc_us_counter_noinc_l=exp(lnpop_ncc_us-((_b[totnpcc_cc_offenses_vc]-1.96*_se[totnpcc_cc_offenses_vc])*delta_vc_noinc))
gen pop_ncc_us_counter_noinc_h=exp(lnpop_ncc_us-((_b[totnpcc_cc_offenses_vc]+1.96*_se[totnpcc_cc_offenses_vc])*delta_vc_noinc))
sort year
label var pop_ncc_us "Real"
label var pop_ncc_us_counter_noinc "Counter. no incr in VC in CC"
label var pop_ncc_us_counter_noinc_l "Counter. l.b."
label var pop_ncc_us_counter_noinc_h "Counter. u.b."
*Counterfactual pop NCC U.S. with increase in crime in CC from 1960 as in NCC
gen pop_ncc_us_counter_incncc=exp(lnpop_ncc_us-(_b[totnpcc_cc_offenses_vc]*delta_vc_incncc)+_b[totnpcc_cc_offenses_vc]*vcnpcc_ncc_us)
gen pop_ncc_us_counter_incncc_l=exp(lnpop_ncc_us-((_b[totnpcc_cc_offenses_vc]-1.96*_se[totnpcc_cc_offenses_vc])*delta_vc_incncc)+((_b[totnpcc_cc_offenses_vc]-1.96*_se[totnpcc_cc_offenses_vc])*vcnpcc_ncc_us))
gen pop_ncc_us_counter_incncc_h=exp(lnpop_ncc_us-((_b[totnpcc_cc_offenses_vc]+1.96*_se[totnpcc_cc_offenses_vc])*delta_vc_incncc)+((_b[totnpcc_cc_offenses_vc]+1.96*_se[totnpcc_cc_offenses_vc])*vcnpcc_ncc_us))
sort year
label var pop_ncc_us "Real"
label var pop_ncc_us_counter_incncc "Counter. incr in VC as NCC"
label var pop_ncc_us_counter_incncc_l "Counter. l.b."
label var pop_ncc_us_counter_incncc_h "Counter. u.b."
*Counterfactual poc NCC U.S. with increase in crime in CC from 1960 in high LB as in low LB
gen pop_ncc_us_counter_inclowlb=exp(lnpop_ncc_us-(_b[totnpcc_cc_offenses_vc]*delta_vc_inclowlb)+_b[totnpcc_cc_offenses_vc]*vcnpcc_cc_lowlb_us)
gen pop_ncc_us_counter_inclowlb_h=exp(lnpop_ncc_us-((_b[totnpcc_cc_offenses_vc]-1.96*_se[totnpcc_cc_offenses_vc])*delta_vc_inclowlb)+((_b[totnpcc_cc_offenses_vc]-1.96*_se[totnpcc_cc_offenses_vc])*vcnpcc_cc_lowlb_us))
gen pop_ncc_us_counter_inclowlb_l=exp(lnpop_ncc_us-((_b[totnpcc_cc_offenses_vc]+1.96*_se[totnpcc_cc_offenses_vc])*delta_vc_inclowlb)+((_b[totnpcc_cc_offenses_vc]+1.96*_se[totnpcc_cc_offenses_vc])*vcnpcc_cc_lowlb_us))
sort year
label var pop_ncc_us "Real"
label var pop_ncc_us_counter_inclowlb "Counter. incr in VC as low LB"
label var pop_ncc_us_counter_inclowlb_l "Counter. l.b."
label var pop_ncc_us_counter_inclowlb_h "Counter. u.b."

gen year2=year+0.25
gen year3=year+0.75

foreach var of varlist pop_*_us*{
    replace `var'=`var'/1000000
}

*Graphs
twoway (line pop_cc_us year, title("Pop. (million) Living in City Centers") xlab(1960(10)1991) lcolor(black)) (line pop_cc_us_counter_noinc year, lcolor(red)) (line pop_cc_us_counter_incncc year, lcolor(blue)) (line pop_cc_us_counter_inclowlb year, lcolor(green)) (rcap pop_cc_us_counter_noinc_l pop_cc_us_counter_noinc_h year, lcolor(red)) (rcap pop_cc_us_counter_incncc_l pop_cc_us_counter_incncc_h year2, lcolor(blue)) (rcap pop_cc_us_counter_inclowlb_l pop_cc_us_counter_inclowlb_h year3, lcolor(green))
graph export ts_counterfactual_all_popcc.png, as(png) replace
twoway (line pop_ncc_us year, title("Pop. (million) Living in Suburbs") xlab(1960(10)1991) lcolor(black)) (line pop_ncc_us_counter_noinc year, lcolor(red)) (line pop_ncc_us_counter_incncc year, lcolor(blue)) (line pop_ncc_us_counter_inclowlb year, lcolor(green)) (rcap pop_ncc_us_counter_noinc_l pop_ncc_us_counter_noinc_h year, lcolor(red)) (rcap pop_ncc_us_counter_incncc_l pop_ncc_us_counter_incncc_h year2, lcolor(blue)) (rcap pop_ncc_us_counter_inclowlb_l pop_ncc_us_counter_inclowlb_h year2, lcolor(green))
graph export ts_counterfactual_all_popncc.png, as(png) replace


*Counterfactual perc CC U.S. without increase in crime in CC from 1960
ivreghdfe perc_cc (totnpcc_cc_offenses_vc = inter_goodtetra), abs(fipsplace_00 year cdivcode#year) cluster(cdivcodeyear)
gen perc_cc_us_counter_noinc=perc_cc_us-(_b[totnpcc_cc_offenses_vc]*delta_vc_noinc)
gen perc_cc_us_counter_noinc_l=perc_cc_us-((_b[totnpcc_cc_offenses_vc]-1.96*_se[totnpcc_cc_offenses_vc])*delta_vc_noinc)
gen perc_cc_us_counter_noinc_h=perc_cc_us-((_b[totnpcc_cc_offenses_vc]+1.96*_se[totnpcc_cc_offenses_vc])*delta_vc_noinc)
sort year
label var perc_cc_us "Real"
label var perc_cc_us_counter_noinc "Counter. no incr in VC in CC"
label var perc_cc_us_counter_noinc_l "Counter. l.b."
label var perc_cc_us_counter_noinc_h "Counter. u.b."
*Counterfactual perc CC U.S. with increase in crime in CC from 1960 as in NCC
gen perc_cc_us_counter_incncc=perc_cc_us-(_b[totnpcc_cc_offenses_vc]*delta_vc_incncc)+_b[totnpcc_cc_offenses_vc]*vcnpcc_ncc_us
gen perc_cc_us_counter_incncc_l=perc_cc_us-((_b[totnpcc_cc_offenses_vc]-1.96*_se[totnpcc_cc_offenses_vc])*delta_vc_incncc)+((_b[totnpcc_cc_offenses_vc]-1.96*_se[totnpcc_cc_offenses_vc])*vcnpcc_ncc_us)
gen perc_cc_us_counter_incncc_h=perc_cc_us-((_b[totnpcc_cc_offenses_vc]+1.96*_se[totnpcc_cc_offenses_vc])*delta_vc_incncc)+((_b[totnpcc_cc_offenses_vc]+1.96*_se[totnpcc_cc_offenses_vc])*vcnpcc_ncc_us)
sort year
label var perc_cc_us "Real"
label var perc_cc_us_counter_incncc "Counter. incr in VC as NCC"
label var perc_cc_us_counter_incncc_l "Counter. l.b."
label var perc_cc_us_counter_incncc_h "Counter. u.b."
*Counterfactual perc CC U.S. with increase in crime in CC from 1960 in high LB as in low LB
gen perc_cc_us_counter_inclowlb=perc_cc_us-(_b[totnpcc_cc_offenses_vc]*delta_vc_inclowlb)+_b[totnpcc_cc_offenses_vc]*vcnpcc_cc_lowlb_us
gen perc_cc_us_counter_inclowlb_h=perc_cc_us-((_b[totnpcc_cc_offenses_vc]-1.96*_se[totnpcc_cc_offenses_vc])*delta_vc_inclowlb)+((_b[totnpcc_cc_offenses_vc]-1.96*_se[totnpcc_cc_offenses_vc])*vcnpcc_cc_lowlb_us)
gen perc_cc_us_counter_inclowlb_l=perc_cc_us-((_b[totnpcc_cc_offenses_vc]+1.96*_se[totnpcc_cc_offenses_vc])*delta_vc_inclowlb)+((_b[totnpcc_cc_offenses_vc]+1.96*_se[totnpcc_cc_offenses_vc])*vcnpcc_cc_lowlb_us)
sort year
label var perc_cc_us "Real"
label var perc_cc_us_counter_inclowlb "Counter. incr in VC as low LB"
label var perc_cc_us_counter_inclowlb_l "Counter. l.b."
label var perc_cc_us_counter_inclowlb_h "Counter. u.b."


*Graphs
drop if year<1960 
twoway (line perc_cc_us year, title("Proportion of People Living in City Centers") xlab(1960(10)1991) lcolor(black)) (line perc_cc_us_counter_noinc year, lcolor(red)) (line perc_cc_us_counter_incncc year, lcolor(blue))  (line perc_cc_us_counter_inclowlb year, lcolor(green)) (rcap perc_cc_us_counter_noinc_l perc_cc_us_counter_noinc_h year, lcolor(red)) (rcap perc_cc_us_counter_incncc_l perc_cc_us_counter_incncc_h year2, lcolor(blue)) (rcap perc_cc_us_counter_inclowlb_l perc_cc_us_counter_inclowlb_h year2, lcolor(green))
graph export ts_counterfactual_all.png, as(png) replace

*Estimates
sum tot_cc_oripop_corr if year==1991
sum pop_cc_us_counter_inclowlb_h if year==1991
di 1000000*`r(mean)'/325
sum pop_cc_us_counter_inclowlb_l if year==1991
di 1000000*`r(mean)'/325
sum perc_cc_us if year==1960
sum perc_cc_us if year==1991
sum perc_cc_us_counter_noinc if year==1991
sum perc_cc_us_counter_incncc if year==1991
sum perc_cc_us_counter_inclowlb if year==1991
sum perc_cc_us_counter_noinc_h if year==1991
sum perc_cc_us_counter_incncc_h if year==1991
sum perc_cc_us_counter_inclowlb_h if year==1991
sum perc_cc_us_counter_inclowlb_l if year==1991

***Alternative graphs: separate counterfactuals
**Pop CC
*Counterfactual 1
twoway (line pop_cc_us year, title("Pop. (million) Living in City Centers") xlab(1960(10)1991) ylab(60(20)160) lcolor(black)) (line pop_cc_us_counter_noinc year, lcolor(red)) (rcap pop_cc_us_counter_noinc_l pop_cc_us_counter_noinc_h year, lcolor(red)) 
graph export ts_counterfactual_all_popcc_cntfct1.png, as(png) replace
*Counterfactual 2
twoway (line pop_cc_us year, title("Pop. (million) Living in City Centers") xlab(1960(10)1991) ylab(60(20)160) lcolor(black)) (line pop_cc_us_counter_incncc year, lcolor(blue)) (rcap pop_cc_us_counter_incncc_l pop_cc_us_counter_incncc_h year2, lcolor(blue)) 
graph export ts_counterfactual_all_popcc_cntfct2.png, as(png) replace
*Counterfactual 3
twoway (line pop_cc_us year, title("Pop. (million) Living in City Centers") xlab(1960(10)1991) ylab(60(20)160) lcolor(black))(line pop_cc_us_counter_inclowlb year, lcolor(green)) (rcap pop_cc_us_counter_inclowlb_l pop_cc_us_counter_inclowlb_h year3, lcolor(green))
graph export ts_counterfactual_all_popcc_cntfct3.png, as(png) replace
**Pop NCC
*Counterfactual 1
twoway (line pop_ncc_us year, title("Pop. (million) Living in Suburbs") xlab(1960(10)1991) ylab(60(20)140) lcolor(black)) (line pop_ncc_us_counter_noinc year, lcolor(red)) (rcap pop_ncc_us_counter_noinc_l pop_ncc_us_counter_noinc_h year, lcolor(red)) 
graph export ts_counterfactual_all_popncc_cntfct1.png, as(png) replace
*Counterfactual 2
twoway (line pop_ncc_us year, title("Pop. (million) Living in Suburbs") xlab(1960(10)1991) ylab(60(20)140) lcolor(black)) (line pop_ncc_us_counter_incncc year, lcolor(blue)) (rcap pop_ncc_us_counter_incncc_l pop_ncc_us_counter_incncc_h year2, lcolor(blue)) 
graph export ts_counterfactual_all_popncc_cntfct2.png, as(png) replace
*Counterfactual 3
twoway (line pop_ncc_us year, title("Pop. (million) Living in Suburbs") xlab(1960(10)1991) ylab(60(20)140) lcolor(black))(line pop_ncc_us_counter_inclowlb year, lcolor(green)) (rcap pop_ncc_us_counter_inclowlb_l pop_ncc_us_counter_inclowlb_h year3, lcolor(green))
graph export ts_counterfactual_all_popncc_cntfct3.png, as(png) replace
**Perc CC
*Counterfactual 1
twoway (line perc_cc_us year, title("Proportion of People Living in City Centers") xlab(1960(10)1991) ylab(0.3(0.1)0.6) lcolor(black)) (line perc_cc_us_counter_noinc year, lcolor(red)) (rcap perc_cc_us_counter_noinc_l perc_cc_us_counter_noinc_h year, lcolor(red)) 
graph export ts_counterfactual_all_perccc_cntfct1.png, as(png) replace
*Counterfactual 2
twoway (line perc_cc_us year, title("Proportion of People Living in City Centers") xlab(1960(10)1991) ylab(0.3(0.1)0.6) lcolor(black)) (line perc_cc_us_counter_incncc year, lcolor(blue)) (rcap perc_cc_us_counter_incncc_l perc_cc_us_counter_incncc_h year2, lcolor(blue)) 
graph export ts_counterfactual_all_perccc_cntfct2.png, as(png) replace
*Counterfactual 3
twoway (line perc_cc_us year, title("Proportion of People Living in City Centers") xlab(1960(10)1991) ylab(0.3(0.1)0.6) lcolor(black))(line perc_cc_us_counter_inclowlb year, lcolor(green)) (rcap perc_cc_us_counter_inclowlb_l perc_cc_us_counter_inclowlb_h year3, lcolor(green))
graph export ts_counterfactual_all_perccc_cntfct3.png, as(png) replace

***Alternative graphs: separate lines and CI
**Pop CC
twoway (line pop_cc_us year, title("Pop. (million) Living in City Centers") xlab(1960(10)1991) lcolor(black)) (line pop_cc_us_counter_noinc year, lcolor(red)) (line pop_cc_us_counter_incncc year, lcolor(blue)) (line pop_cc_us_counter_inclowlb year, lcolor(green))
graph export ts_counterfactual_all_popcc_estim.png, as(png) replace
twoway (line pop_cc_us year, title("Pop. (million) Living in City Centers") xlab(1960(10)1991) lcolor(black)) (rcap pop_cc_us_counter_noinc_l pop_cc_us_counter_noinc_h year, lcolor(red)) (rcap pop_cc_us_counter_incncc_l pop_cc_us_counter_incncc_h year2, lcolor(blue)) (rcap pop_cc_us_counter_inclowlb_l pop_cc_us_counter_inclowlb_h year3, lcolor(green))
graph export ts_counterfactual_all_popcc_ci.png, as(png) replace
**Pop NCC
twoway (line pop_ncc_us year, title("Pop. (million) Living in Suburbs") xlab(1960(10)1991) lcolor(black)) (line pop_ncc_us_counter_noinc year, lcolor(red)) (line pop_ncc_us_counter_incncc year, lcolor(blue)) (line pop_ncc_us_counter_inclowlb year, lcolor(green))
graph export ts_counterfactual_all_popncc_estim.png, as(png) replace
twoway (line pop_ncc_us year, title("Pop. (million) Living in Suburbs") xlab(1960(10)1991) lcolor(black)) (rcap pop_ncc_us_counter_noinc_l pop_ncc_us_counter_noinc_h year, lcolor(red)) (rcap pop_ncc_us_counter_incncc_l pop_ncc_us_counter_incncc_h year2, lcolor(blue)) (rcap pop_ncc_us_counter_inclowlb_l pop_ncc_us_counter_inclowlb_h year3, lcolor(green))
graph export ts_counterfactual_all_popncc_ci.png, as(png) replace
**Perc CC
twoway (line perc_cc_us year, title("Proportion of People Living in City Centers") xlab(1960(10)1991) lcolor(black)) (line perc_cc_us_counter_noinc year, lcolor(red)) (line perc_cc_us_counter_incncc year, lcolor(blue)) (line perc_cc_us_counter_inclowlb year, lcolor(green))
graph export ts_counterfactual_all_perccc_estim.png, as(png) replace
twoway (line perc_cc_us year, title("Proportion of People Living in City Centers") xlab(1960(10)1991) lcolor(black)) (rcap perc_cc_us_counter_noinc_l perc_cc_us_counter_noinc_h year, lcolor(red)) (rcap perc_cc_us_counter_incncc_l perc_cc_us_counter_incncc_h year2, lcolor(blue)) (rcap perc_cc_us_counter_inclowlb_l perc_cc_us_counter_inclowlb_h year3, lcolor(green))
graph export ts_counterfactual_all_perccc_ci.png, as(png) replace







///////////////////////
///FIGURE A.11
//////////////////////

***Baum-snow (2007) data (taken from panel.do)
clear
set more off
set matsize 800

set mem 80m

*Create temp file with state-level hwy data for instrument **

use "finaldata\hwy-allyr-state.dta"

collapse (sum) lenc, by(year)

sort year

replace year=1900+year

gen sshrc = lenc/lenc[_N]
sort year

tempfile temp1
save `temp1', replace

use "finaldata\final_cc_data.dta", clear

sort year
merge m:1 year using `temp1'

drop _merge

drop if fipsplace_00==.
xtset fipsplace_00 year

drop if year>1991

*Create aggregate variables
egen vcn_cc_us=total( totn_cc_offenses_vc),by(year)
egen vcn_ncc_us=total( totn_ncc_offenses_vc),by(year)
egen pop_cc_us=total(tot_cc_oripop_corr),by(year)
egen pop_ncc_us=total(tot_ncc_oripop_corr),by(year)
gen vcnpcc_cc_us=vcn_cc_us/pop_cc_us
gen vcnpcc_ncc_us=vcn_ncc_us/pop_ncc_us
gen perc_cc_us=pop_cc_us/(pop_cc_us+pop_ncc_us)

sum vcnpcc_cc_us
local vcmax=`r(max)'
gen vcnpcc_cc_us_max=vcnpcc_cc_us/`vcmax'

gen south=(cdivcode==2 | cdivcode==7 | cdivcode==9)
gen popblk=pctblk*pop
egen popblk_south_2=total(popblk) if south==1, by(year)
egen popblk_south=max(popblk_south_2), by(year)
drop popblk_south_2
egen popblk_us=total(popblk), by(year)
gen popblk_percsouth=popblk_south/popblk_us

keep if FMSA==40
*keep if year==1960 | year==1970 | year==1980 | year==1990

label var perc_cc_us "Share Pop CC"
label var vcnpcc_cc_us_max "Violent crime in CC (norm.)"
label var sshrc "Prop. highways built"
label var popblk_percsouth "Prop. U.S. blacks in South"

drop if year==1950
sort year

line vcnpcc_cc_us_max sshrc   popblk_percsouth year



///////////////////////////////////////////////////////////////////////////////////////////
///TABLE A.5
///////////////////////////////////////////////////////////////////////////////////////////

***Baum-snow (2007) data (taken from panel.do)
clear
set more off
set matsize 800

set mem 80m

*Create temp file with state-level hwy data for instrument **

use "finaldata\hwy-allyr-state.dta"

collapse (sum) lenc, by(year)

sort year

replace year=1900+year

gen sshrc = lenc/lenc[_N]
sort year

tempfile temp1
save `temp1', replace

use "finaldata\final_cc_data.dta", clear

sort year
merge m:1 year using `temp1'

drop _merge

drop if fipsplace_00==.
xtset fipsplace_00 year

drop if year>1991

*Create instrument and outcome
g good_soil = (ph1_plc_wtm_wtm_0_r>=6.8 & ph1_plc_wtm_wtm_0_r<=7.7)
g bad_soil=1-good_soil
gen inter_goodtetra=good_soil*tetra_corr
gen inter_badtetra=(1-good_soil)*tetra_corr
g perc_cc =  tot_cc_oripop_corr / (tot_ncc_oripop_corr + tot_cc_oripop_corr)
gen vc_pc=totnpcc_cc_offenses_vc*1000

*Baum-Snow (2007) variables
gen raysxplan = sshrc*rays_planc
sum raysxplan
local raymax=`r(max)'
gen raysxplan_max=raysxplan/`raymax'
replace pop = pop/1000000
replace lagpop = lagpop/1000000
replace cpop2 = cpop2/1000000
gen lpop = log(pop)
gen lcpop = log(cpop)
gen lcpop2 = log(cpop2)

gen POP50 = pop if year==50
egen pop50 = max(POP50), by(FMSA)
gen CPOP50 = cpop2 if year==50
egen cpop50 = max(CPOP50), by(FMSA)

*Create aggregate variables
egen vcn_cc_us=total( totn_cc_offenses_vc),by(year)
egen vcn_ncc_us=total( totn_ncc_offenses_vc),by(year)
egen pop_cc_us=total(tot_cc_oripop_corr),by(year)
egen pop_ncc_us=total(tot_ncc_oripop_corr),by(year)
gen vcnpcc_cc_us=vcn_cc_us/pop_cc_us
gen vcnpcc_ncc_us=vcn_ncc_us/pop_ncc_us
gen perc_cc_us=pop_cc_us/(pop_cc_us+pop_ncc_us)
g lnpop_cc = ln(tot_cc_oripop_corr)

*Generate 1960 variables
foreach var of varlist cpctblk pctblk{
gen `var'_1960_2=`var' if year==1960
egen `var'_1960=max(`var'_1960_2), by(FMSA)
drop `var'_1960_2
}
gen prop_black_1960=cpctblk_1960/pctblk_1960
g area_plc_sqkm=area_plc/1000000
g area_ncc_sqkm=area_ncc/1000000
gen pop_cc_1960_2=tot_cc_oripop_corr if year==1960
egen pop_cc_1960=max(pop_cc_1960_2), by(FMSA)
gen dens_cc_1960=pop_cc_1960/area_plc_sqkm
g dens_cc=tot_cc_oripop_corr/area_plc_sqkm
g dens_ncc=tot_ncc_oripop_corr/area_ncc_sqkm
egen rays_planc_1947=max(rays_planc), by(fipsplace_00)

*Create heterogeneities
gen inter_rays_planc=inter_badtetra*rays_planc
gen inter_rays_planc_1947=inter_badtetra*rays_planc_1947
gen inter_cpctblk_1960=inter_badtetra*cpctblk_1960
gen inter_prop_black_1960=inter_badtetra*prop_black_1960
gen inter_dens_cc_1960=inter_badtetra*dens_cc_1960

label var racc "Rays"
label var rays_planc "Rays in plan"
label var raysxplan_max "Rays in plan x Prop. hgw (norm.)"
label var vc_pc "Violent crime"
label var inter_badtetra "High LB x Lead"
label var inter_badtetra "High LB x Lead"
label var inter_cpctblk_1960 "High LB x Lead x Blacks CC 1960"
label var inter_prop_black_1960 "High LB x Lead x Blacks CC / MSA 1960"
label var inter_rays_planc "High LB x Lead x Planned highways CC"
label var inter_rays_planc_1947 "High LB x Lead x Planned highways CC"
label var inter_dens_cc_1960 "High LB x Lead x Density CC 1960"

egen cregcodeyear=group(cregcode year)
egen cdivcodeyear=group(cdivcode year)


g n_black = (cpop * cpctblk) / 100


file open myfile using "quant_parteff.tex", write replace

file write myfile " \begin{tabular}{lcccc} \hline"
file write myfile "     & \textbf{Eff. 1 VC CC} &  \textbf{Eff. mechanism} & \textbf{Eff. 1 VC CC on Pop CC} &  \\  " _n
file write myfile "  \textbf{Variable}   & \textbf{on mechanism} &  \textbf{on Pop CC} & \textbf{via mechanism} & \textbf{Share effect} \\ \hline " _n


********************
*** THE EFFECT OF VC ON MECH
***********************

**HIGHWAY
ivreghdfe racc (vc_pc = inter_badtetra), abs(fipsplace_00 year cregcode#year) cluster(cregcodeyear)
*1 vc = .0448485 rays
local eff_vc_racc=_b[vc_pc]

****BLACK
ivreghdfe cpctblk (vc_pc = inter_badtetra), abs(fipsplace_00 year cregcode#year) cluster(cregcodeyear)
*1 vc = 0.81% more blacks -> 421 blacks
local eff_vc_black_perc=_b[vc_pc]
sum n_black
*sum tot_cc_oripop_corr
local eff_vc_black=(`eff_vc_black_perc'/100)*`r(mean)'
di `eff_vc_black'

***TOTAL EFFECT
ivreghdfe lnpop_cc (vc_pc = inter_badtetra), abs(fipsplace_00 year cdivcode#year) cluster(cdivcodeyear)
local eff_popcc=-100*(_b[vc_pc])

***********************************
**** The effect of mech on ln(pop_cc)
************************************
* 9 percent decline in central city population for each additional ray. (pg 13)
local eff_racc_popcc=0.09*100

* each black arrival led to 2.7 white departures
local eff_black_popcc_num=2.7
*local eff_black_popcc_num=1.7
sum tot_cc_oripop_corr
local eff_black_popcc=`eff_black_popcc_num'/`r(mean)'
di `eff_black_popcc'*100

 
*********************
**INDIRECT EFFECT OF 1 VC INCREASE
*******************************

**HIGHWAY
* 1 vc = -0.004 change in ln(tot_cc_oripop_corr)
local eff_vc_racc_popcc=`eff_vc_racc'*`eff_racc_popcc'
di `eff_vc_racc_popcc'

**Black
* 1 vc =  - 3002 change in  tot_cc_oripop_corr
* avg tot_cc_oripop_corr =  233780
* 1 vc = - 0.013 change in ln(tot_cc_oripop_corr)
local eff_vc_black_popcc=100*`eff_vc_black'*`eff_black_popcc'
di `eff_vc_black_popcc'


****total effect 100
**HIGHWAY EFFECT 9.3%
local eff_racc=100*`eff_vc_racc_popcc'/`eff_popcc'
di 100*`eff_vc_racc_popcc'/`eff_popcc'
**BOUSTAN EFFECT 31.8%
local eff_black=100*`eff_vc_black_popcc'/`eff_popcc'
di 100*`eff_vc_black_popcc'/`eff_popcc'

**DIRECT EFFECT 
local eff_vc=100-`eff_racc'-`eff_black' 
di 1-(`eff_vc_racc_popcc'+`eff_vc_black_popcc' )/`eff_popcc'

local eff_vc_racc = string(`eff_vc_racc',"%8.3f") 
local eff_vc_racc_popcc = string(`eff_vc_racc_popcc',"%8.2f") 
local eff_racc = string(`eff_racc',"%8.2f") 

local eff_vc_black_perc = string(`eff_vc_black_perc',"%8.2f") 
local eff_vc_black_popcc = string(`eff_vc_black_popcc',"%8.2f") 
local eff_black = string(`eff_black',"%8.2f") 

local eff_popcc = string(`eff_popcc',"%8.2f") 
local eff_vc = string(`eff_vc',"%8.2f") 

file write myfile "Highways &  $\uparrow$ `eff_vc_racc' highways	&  1 highway $\downarrow$ Pop CC by `eff_racc_popcc'\%  &   $\downarrow$ Pop CC by `eff_vc_racc_popcc'\% due to highway & `eff_racc'\%   \\ " _n

file write myfile "Blacks & $\uparrow$ `eff_vc_black_perc' p.p. blacks CC	&  1 black CC $\downarrow$ whites CC by `eff_black_popcc_num'  &   $\downarrow$ Pop CC by `eff_vc_black_popcc'\% due to blacks CC & `eff_black'\%   \\ " _n

file write myfile "Violent crime &   &   &   $\downarrow$ Pop CC by `eff_popcc'\%  & `eff_vc'\%   \\ " _n

file write myfile " \end{tabular}"
file close myfile






///////////////////////////////////////////////////////////////////////////////////////////
///TABLE A.6 
///////////////////////////////////////////////////////////////////////////////////////////

***Baum-snow (2007) data  
clear
set more off
set matsize 800

set mem 80m

*Create temp file with state-level hwy data for instrument **

use "finaldata\hwy-allyr-state.dta"

collapse (sum) lenc, by(year)

sort year

replace year=1900+year

gen sshrc = lenc/lenc[_N]
sort year

tempfile highway
save `highway', replace


use "finaldata\final_cc_data.dta", clear

sort year
merge m:1 year using `highway'

drop _merge

drop if fipsplace_00==.
xtset fipsplace_00 year

drop if year>1991

*Create instrument and outcome
g good_soil = (ph1_plc_wtm_wtm_0_r>=6.8 & ph1_plc_wtm_wtm_0_r<=7.7)
g bad_soil=1-good_soil
gen inter_goodtetra=good_soil*tetra_corr
gen inter_badtetra=(1-good_soil)*tetra_corr
g perc_cc =  tot_cc_oripop_corr / (tot_ncc_oripop_corr + tot_cc_oripop_corr)
gen vc_pc=totnpcc_cc_offenses_vc*1000

*Baum-Snow (2007) variables
gen raysxplan = sshrc*rays_planc
sum raysxplan
local raymax=`r(max)'
gen raysxplan_max=raysxplan/`raymax'
replace pop = pop/1000000
replace lagpop = lagpop/1000000
replace cpop2 = cpop2/1000000
gen lpop = log(pop)
gen lcpop = log(cpop)
gen lcpop2 = log(cpop2)

gen POP50 = pop if year==50
egen pop50 = max(POP50), by(FMSA)
gen CPOP50 = cpop2 if year==50
egen cpop50 = max(CPOP50), by(FMSA)

*Create aggregate variables
egen vcn_cc_us=total( totn_cc_offenses_vc),by(year)
egen vcn_ncc_us=total( totn_ncc_offenses_vc),by(year)
egen pop_cc_us=total(tot_cc_oripop_corr),by(year)
egen pop_ncc_us=total(tot_ncc_oripop_corr),by(year)
gen vcnpcc_cc_us=vcn_cc_us/pop_cc_us
gen vcnpcc_ncc_us=vcn_ncc_us/pop_ncc_us
gen perc_cc_us=pop_cc_us/(pop_cc_us+pop_ncc_us)

foreach var of varlist cpctblk pctblk{
gen `var'_1960_2=`var' if year==1960
egen `var'_1960=max(`var'_1960_2), by(FMSA)
drop `var'_1960_2
}
gen south=(cdivcode==2 | cdivcode==7 | cdivcode==9)
egen pctblk_south_2=mean(pctblk) if south==1, by(year)
egen pctblk_south=max(pctblk_south_2), by(year)
drop pctblk_south_2
gen pctblk_south_1960=pctblk_south*pctblk_1960
sum pctblk_south_1960
local blkmax=`r(max)'
gen pctblk_south_1960_max=pctblk_south_1960/`blkmax'

label var racc "Rays"
label var rays_planc "Rays in plan"
label var raysxplan_max "Rays in plan x Prop. hgw (norm.)"
label var vc_pc "Violent crime"
label var inter_badtetra "High LB x Lead"
label var pctblk_south_1960_max "Blacks CC 1960 x Black South US (norm.)"

ivreghdfe perc_cc pctblk_south_1960_max (vc_pc racc= inter_badtetra raysxplan_max) if pop50>.1 & cpop50>.05, absorb(fipsplace_00 year) cluster(FMSA)
local ff = trim("`: display %10.2f e(cdf)'")
outreg2 using  table_horse, keep(vc_pc racc pctblk_south_1960_max) tex(frag) nocon noni nor2 nonotes label ctitle("Sh pop CC") addtext(MSA FE, YES, Year FE, YES, Estimation, IV, F, `ff') replace

reghdfe vc_pc inter_badtetra raysxplan_max pctblk_south_1960_max if pop50>.1 & cpop50>.05, absorb(fipsplace_00 year) vce(cluster FMSA)
outreg2 using  table_a6, keep(inter_badtetra raysxplan_max pctblk_south_1960_max) tex(frag) nocon noni nor2 nonotes label ctitle("Violent crime") addtext(MSA FE, YES, Year FE, YES, Estimation, OLS, F, .)

reghdfe racc inter_badtetra raysxplan_max pctblk_south_1960_max if pop50>.1 & cpop50>.05, absorb(fipsplace_00 year) vce(cluster FMSA)
outreg2 using  table_a6, keep(inter_badtetra raysxplan_max pctblk_south_1960_max) tex(frag) nocon noni nor2 nonotes label ctitle("Rays") addtext(MSA FE, YES, Year FE, YES, Estimation, OLS, F, .)

reghdfe perc_cc inter_badtetra raysxplan_max pctblk_south_1960_max if pop50>.1 & cpop50>.05, absorb(fipsplace_00 year) cluster(FMSA)
outreg2 using  table_a6, keep(raysxplan_max inter_badtetra pctblk_south_1960_max) tex(frag) nocon noni nor2 nonotes label ctitle("Sh pop CC") addtext(MSA FE, YES, Year FE, YES, Estimation, OLS, F, .)


///////////////////////////////////////////////////////////////////////////////////////////
//FIGURE A.12
///////////////////////////////////////////////////////////////////////////////////////////

reghdfe perc_cc inter_badtetra raysxplan_max if pop50>.1 & cpop50>.05, absorb(fipsplace_00 year) cluster(FMSA)

gen perc_cc_us_nobad=perc_cc_us-_b[inter_badtetra]
gen perc_cc_us_nohgw=perc_cc_us-_b[raysxplan_max]
gen perc_cc_us_nobadhgw=perc_cc_us-_b[inter_badtetra]-_b[raysxplan_max]

gen perc_cc_us_1960_2=perc_cc_us if year==1960
egen perc_cc_us_1960=max(perc_cc_us_1960_2)
gen perc_cc_us_1990_2=perc_cc_us if year==1990
egen perc_cc_us_1990=max(perc_cc_us_1990_2)
drop perc_cc_us_1990_2 perc_cc_us_1990_2

label var perc_cc_us_1960 "Real 1960"
label var perc_cc_us_1990 "Real 1990"
label var perc_cc_us_nobad "No lead"
label var perc_cc_us_nohgw "No highways"
label var perc_cc_us_nobadhgw "No lead and highways"


graph bar perc_cc_us_1960 perc_cc_us_1990 ///
		  perc_cc_us_nobad perc_cc_us_nohgw ///
		  perc_cc_us_nobadhgw , legend(label(1 "Real 1960") label(2 "Real 1990") ///
		  label(3 "No lead") label(4 "No highways")   ///
		  label(5 "No lead and highways") )
graph export  figure_counter_horse.png, as(png) replace
